import {app,router,store} from './app'


router.beforeEach((to,from,next)=>{
	var token=store.state.user.token;
	console.log(to.path,from.path,token)
	if(token=="" || token==null || token==undefined){
		var user=Vue.storage.getItem('user');
		if(user && typeof user =="string"){
			var _user={};
			try{
				_user=JSON.parse(user);
			}catch(e){
				console.log('catch')
				Vue.storage.removeItem('user');
				if(to.path!="/login"){
					next("login")
				}else{
					next();
				}
			}finally{
				console.log('finally')
				store.commit('SET_ONLINE_USER',_user);
				if(to.path=="/login"){
					next('/')
				}else{
					next();
				}
			}
		}else{
			console.log('else1')
			if(to.path!="/login"){
				next('login')
			}else{
				next();
			}
		}
	}else{
		console.log('else')
		if(to.path=="/login"){
			next('/')
		}else{
			next();
		}
	}
})

app.$mount('#vue')